#!/usr/bin/python
# -*- coding: UTF-8 -*-

#! encoding = utf-8

from lib.follow import Follow
from lib.func import reportServer
import sys, random, logging

def start(device_id, p_name):
    self = Follow(device_id)
    self.open_douyin_by_packname(p_name)
    not_login = self.check_is_not_login()
    if not_login:
        return
    
    self.click_text_and_check("首页")
    self.sleep(5)
    if not self.click_city():
        return
    
    runTongcheng(self, 0)
    self.click_text_and_check("推荐")
    self.sleep(4)
    self.swipe_up()

def runRecommend(self: Follow, trys=0):
    return

def runTongcheng(self: Follow, trys=0):
    if trys > 100:
        return
    logging.warning("进入同城")
    self.swipe_up(random.randint(2, 8))
    self.click_video()
    if self.device(text="取消").exists(timeout=3):
        logging.warning("进入直播")
        self.click_text_and_check("继续观看")
        self.sleep(random.randint(30, 100))
        self.press_back()
        self.sleep(2)
        return runTongcheng(self, trys+1)
    
    # 随机观看1-35S
    self.sleep(random.randint(1, 35))
    if random.randint(1,100) > 70:
        logging.warning("点赞了")
        self.zan()

    if random.randint(1, 100) > 85:
        logging.warning("开始评论了")
        self.comment("hello")

    self.press_back()
    self.sleep(2)
    return runTongcheng(self, trys+1)

if __name__ == "__main__":
    device_id = sys.argv[1]
    p_name = sys.argv[2]
    start(device_id, p_name)